<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const inputText = ref('')

const handleSubmit = () => {
  if (inputText.value.trim()) {
    const question = inputText.value.trim()
    inputText.value = '' // 清空输入框
    router.push({
      path: '/chat',
      query: { question }
    })
  }
}

const autoResize = (event) => {
  const textarea = event.target
  textarea.style.height = 'auto'
  const newHeight = Math.min(textarea.scrollHeight, 150) // 5 lines max (30px per line)
  textarea.style.height = newHeight + 'px'
  
  // 如果内容高度超过最大高度，滚动到底部
  if (textarea.scrollHeight > 120) {
    textarea.scrollTop = textarea.scrollHeight
  }
}
</script>

<template>
  <div class="home">
    <h1 class="content">
      欢迎访问我的网站
    </h1>
    <div class="input-container">
      <textarea 
        v-model="inputText"
        placeholder="给DeepSeek发送消息"
        class="input-box"
        rows="1"
        @input="autoResize"
      ></textarea>
      <button 
        @click="handleSubmit"
        :disabled="!inputText.trim()"
        class="submit-button"
      >
        →
      </button>
    </div>
  </div>
</template>

<style scoped>

.home {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 90vh;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding-top: 10vh;
  text-align: center;
  overflow: hidden;
  overflow: hidden;
}

.content {
  font-size: 50px;
  margin-top: 2rem;
  opacity: 0;
  transform: translateY(50px);
  animation: slideUp 1s ease-out forwards;
  font-weight: 600;
  background: linear-gradient(45deg, #007cf0, #00dfd8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.input-container {
  display: flex;
  gap: 10px;
  margin-top: 4rem;
  justify-content: center;
  align-items: flex-start;
}

.input-box {
  padding: 12px 20px;
  font-size: 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  width: 500px;
  transition: border-color 0.3s ease;
  resize: none;
  overflow-y: scroll;
  min-height: 30px;
  max-height: 150px;
  line-height: 1.5;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

/* 隐藏 Webkit 浏览器的滚动条 */
.input-box::-webkit-scrollbar {
  display: none;
}

.input-box:focus {
  outline: none;
  border-color: #007cf0;
}

.submit-button {
  padding: 12px 24px;
  font-size: 20px;
  background: linear-gradient(45deg, #007cf0, #00dfd8);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 60px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.submit-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.submit-button:not(:disabled):hover {
  opacity: 0.9;
  transform: translateX(5px);
}
</style>
